package com.itheima.recursion_multi;

import java.util.LinkedList;

/**
 * @FileName E02HanoiTower
 * @Description
 * @Author Sword
 * @date 2025-03-14
 **/

public class E02HanoiTower {

    static LinkedList<Integer> a = new LinkedList<>();

    static LinkedList<Integer> b = new LinkedList<>();

    static LinkedList<Integer> c = new LinkedList<>();

    private static void init(int n) {
        for (int i = n; i >= 1; i--) {
            a.addLast(i);
        }
    }

    /**
     * @param n 圆盘个数
     * @param a 源
     * @param b 借
     * @param c 目
     */
    private static void move(int n, LinkedList<Integer> a, LinkedList<Integer> b, LinkedList<Integer> c) {
        if (n == 0) {
            return;
        }
        //递归将a柱n-1个圆盘挪到b柱
        move(n - 1, a, c, b);
        //将a柱最大的圆盘移动到c柱
        c.addLast(a.removeLast());
        print();
        //递归将b柱的n-1个圆盘挪回c柱
        move(n - 1, b, a, c);
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        init(3);
        print();
        move(3, a, b, c);
        long end = System.currentTimeMillis();
        System.out.println("执行时间：" + (end - start) + "ms");

    }

    private static void print() {
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println("=======================");
    }
}
